package com.sw.study.springmvc.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by sw on 2020/4/18.
 */

public class SecurityInterceptor implements HandlerInterceptor {
    /**
     * controller 前值拦截
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String userName=request.getParameter("userName");
        String password = request.getParameter("password");
        if("admin".equals(userName) && "admin".equals(password)){
            return true;
        }
        System.out.println("asdasd");
        response.sendRedirect("login");
        return false;
    }


    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }


    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}